package com.mva.Customer_DAO;

import com.mva.Address_DAO.Address;
import com.mva.Codes_DAO.CodeValueDAO;
import com.mva.User_DAO.User;
import com.mva.common.DataDictionaryConstants;
import com.mva.common.Displayable;
import com.mva.common.Validator;

/*******************************************************************************
 The <big><b>Customer</b></big> class implements the <b>Displayable</b> &
 <b>Cloneable</b> interfaces to create an <b>Customer</b> object
 <br><br>
 @author D.Merkling - 1:33:38 PM - Aug 22, 2011
 <br><br>
 @version 1.2  
*******************************************************************************/
public class Customer implements Displayable, Cloneable, DataDictionaryConstants
  {

   private int    Cust;
   private String TIN;
   private String Nm_Fst;
   private String Nm_Lst;
   private int    Addr;
   private String Phn;
   private String Phn2;
   private String Eml;
   private String Eml2;
	   
   // Declare a class variable
   private static CodeValueDAO codevalueDAO = null;

   /*******************************************************************************
	This constructor creates a new <b>Customer</b> object with default values
   *******************************************************************************/
   public Customer ()
	 {
	  this.Cust   = 1;
	  this.TIN    = " ";
	  this.Nm_Fst = " ";
	  this.Nm_Lst = " ";
	  this.Addr   = 0;
	  this.Phn    = " ";
	  this.Phn2   = " ";
	  this.Eml    = " ";
	  this.Eml2   = " ";
	 }

   /*******************************************************************************
	This constructor creates a new <b>Customer</b> object with attribute values as
	defined by the provided parameters
	<br><br>
	@param Cust An <b><i>int</i></b> variable
	@param TIN (Tax Identification Number) A <b><i>String</i></b> variable
	@param First name A <b><i>String</i></b> variable
	@param Last name A <b><i>String</i></b> variable
	@param Addr An <b><i>int</i></b> variable
	@param Phone #1 A <b><i>String</i></b> variable
	@param Phone #2 A <b><i>String</i></b> variable
	@param Email #1 A <b><i>String</i></b> variable
	@param Email #2 A <b><i>String</i></b> variable
   *******************************************************************************/
   public Customer (int Cust, String TIN, String Nm_Fst, String Nm_Lst, int Addr, String Phn, String Phn2,
		            String Eml, String Eml2)
	 {
	  this.Cust   = Cust;
	  this.TIN    = TIN;
	  this.Nm_Fst = Nm_Fst;
	  this.Nm_Lst = Nm_Lst;
	  this.Addr   = Addr;
	  this.Phn    = Phn;
	  this.Phn2   = Phn2;
	  this.Eml    = Eml;
	  this.Eml2   = Eml2;
	 }
   
   /*******************************************************************************
	Clones the current <b>Customer</b> object to create a new one
	<br><br>
	@return Customer - A <b>Customer</b> object
	@throws CloneNotSupportedException 
   *******************************************************************************/
   public Object clone () throws CloneNotSupportedException
	 {
	  return super.clone();
	 }

   /*******************************************************************************
	Sets the <b><i>int</i></b> <b>Cust</b> attribute for the current
	<b>Customer</b> object
	<br><br>
	The value must be greater than zero
	<br><br>
	@param Cust An <b><i>int</i></b> variable
   *******************************************************************************/
   public void setCust (int cust)
	 {
	  int tmpCust = cust;
	  if (tmpCust < 1)
	    {
		 tmpCust  = 1;  
	    }
	  this.Cust   = tmpCust;
	 }

   /*******************************************************************************
	Retrieves the <b><i>int</i></b> <b>Cust</b> attribute from the current
	<b>Customer</b> object
	@return Cust - An <b><i>int</i></b> variable
   *******************************************************************************/
   public int getCust ()
	 {
	  return Cust;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>TIN</b> attribute for the current
	<b>Customer</b> object
	<br><br>
	The value must be uppercase, trimmed, & left-justified
	<br><br>
	@param TIN A <b><i>String</i></b> variable
   *******************************************************************************/
   public void setTIN (String tin)
	 {
	  String tmpTIN = TIN.trim();
	         tmpTIN = tmpTIN.toUpperCase();
	  this.TIN      = tmpTIN;
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>TIN</b> attribute from the current
	<b>Customer</b> object
	@return Addr - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getTIN ()
	 {
	  return TIN;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>Nm_Fst</b> attribute for the current
	<b>Customer</b> object
	<br><br>
	The value must be trimmed & left-justified
	<br><br>
	@param Nm_Fst A <b><i>String</i></b> variable
   *******************************************************************************/
   public void setNmFst (String nm)
	 {
	  String tmpNm = nm.trim();
	  this.Nm_Fst  = tmpNm;
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>Nm_Fst</b> attribute from the current
	<b>Customer</b> object
	@return Nm_Fst - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getNmFst ()
	 {
	  return Nm_Fst;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>Nm_Lst</b> attribute for the current
	<b>Customer</b> object
	<br><br>
	The value must be trimmed & left-justified
	<br><br>
	@param Nm_Lst A <b><i>String</i></b> variable
   *******************************************************************************/
   public void setNmLst (String nm)
	 {
	  String tmpNm = nm.trim();
	  this.Nm_Lst  = tmpNm;
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>Nm_Lst</b> attribute from the current
	<b>Customer</b> object
	@return Nm_Lst - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getNmLst ()
	 {
	  return Nm_Lst;
	 }
   
   /*******************************************************************************
	Sets the <b><i>int</i></b> <b>Addr</b> attribute for the current
	<b>Customer</b> object
	<br><br>
	The value must be an unsigned, positive integer
	<br><br>
	@param Addr An <b><i>int</i></b> variable
   *******************************************************************************/
   public void setAddr (int addr)
	 {
	  this.Addr = addr;
	 }

   /*******************************************************************************
	Retrieves the <b><i>int</i></b> <b>Addr</b> attribute from the current
	<b>Customer</b> object
	@return Addr - An <b><i>int</i></b> variable
   *******************************************************************************/
   public int getAddr ()
	 {
	  return Addr;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>phone #1</b> attribute for the current
	<b>Customer</b> object
	<br><br>
	The value must be trimmed, left-justified, & formatted as a proper phone
	number - 999-999-9999
	<br><br>
	@param Phone #1 A <b><i>String</i></b> variable
	@return isValid - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setPhn (String inPhn)
	 {
	  String phn1 = inPhn.trim();
	  String phn2 = "";
             phn2 = Validator.validatePhone(phn1);
	  if (phn2.equals("**BAD**"))
	    {
		 System.out.println("Phone #1 not valid; saved as blanks");
		 return false;
	    }
	  else
	    {
		 this.Phn = phn2;
		 return true;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>phone #1</b> attribute from the current
	<b>Customer</b> object
	<br><br>
	@return Phone #1 - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getPhn ()
	 {
	  return Phn;
	 }

   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>phone #2</b> attribute for the current
	<b>Customer</b> object
	<br><br>
	The value must be trimmed, left-justified, & formatted as a proper phone
	number - 999-999-9999
	<br><br>
	@param Phone #2 A <b><i>String</i></b> variable
	@return isValid - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setPhn2 (String inPhn)
	 {
	  String phn1 = inPhn.trim();
	  String phn2 = "";
             phn2 = Validator.validatePhone(phn1);
	  if (phn2.equals("**BAD**"))
	    {
		 System.out.println("Phone #2 not valid; saved as blanks");
		 return false;
	    }
	  else
	    {
		 this.Phn = phn2;
		 return true;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>phone #2</b> attribute from the current
	<b>Customer</b> object
	<br><br>
	@return Phone #2 - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getPhn2 ()
	 {
	  return Phn;
	 }
   
   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>email #1</b> attribute for the current
	<b>Customer</b> object
	<br><br>
	The value must be trimmed, left-justified, & formatted as a proper email
	address - xxxxxxxx@yyyyyyyy.zzz
	<br><br>
	@param Email #1 A <b><i>String</i></b> variable
	@return isValid - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setEmail (String inEml)
	 {
	  String  eml1    = inEml.trim();
	  boolean isValid = false;
	          isValid = Validator.validateEmail(eml1);
	  if (isValid)
	    {
		 this.Eml = eml1;
		 return true;
	    }
	  else
	    {
		 System.out.println("Email #1 not valid format; saved as blanks");
		 return false;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>email #1</b> attribute from the current
	<b>Customer</b> object
	<br><br>
	@return Email #1 - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getEmail ()
	 {
	  return Eml;
	 }
   
   /*******************************************************************************
	Sets the <b><i>String</i></b> <b>email #2</b> attribute for the current
	<b>Customer</b> object
	<br><br>
	The value must be trimmed, left-justified, & formatted as a proper email
	address - xxxxxxxx@yyyyyyyy.zzz
	<br><br>
	@param Email #2 A <b><i>String</i></b> variable
	@return isValid - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean setEmail2 (String inEml)
	 {
	  String  eml1    = inEml.trim();
	  boolean isValid = false;
	          isValid = Validator.validateEmail(eml1);
	  if (isValid)
	    {
		 this.Eml = eml1;
		 return true;
	    }
	  else
	    {
		 System.out.println("Email #2 not valid format; saved as blanks");
		 return false;
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>String</i></b> <b>email #2</b> attribute from the current
	<b>Customer</b> object
	<br><br>
	@return Email #2 - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getEmail2 ()
	 {
	  return Eml;
	 }
   
   /*******************************************************************************
	Determines whether or not all of the attribute values of one <b>Customer</b>
	object are equal to all of the attribute values of a second <b>Customer</b>
	object
	<br><br>
	@param object A	<b>Customer</b> object
	@return true/false - A <b><i>boolean</i></b> variable
   *******************************************************************************/
   public boolean equals(Object object)
     {
      if (object instanceof Customer)
        {
    	 Customer cust2 = (Customer) object;
         if (Cust == cust2.getCust()         &&
             TIN.equals(cust2.getTIN())      &&
             Nm_Fst.equals(cust2.getNmFst()) &&
             Nm_Lst.equals(cust2.getNmLst()) &&
             Addr == cust2.getAddr()         &&
             Phn.equals(cust2.getPhn())      &&
             Phn2.equals(cust2.getPhn2())    &&
             Eml.equals(cust2.getEmail())    &&
             Eml2.equals(cust2.getEmail2()))
         return true;
        }
      return false;
     }
   
   /*******************************************************************************
	Retrieves a formatted list of the attribute values of the current
	<b>Customer</b> object
	<br><br>
	@return string - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String toString()
	 {
	  return "Customer ID: " + this.Cust        + "\n" +
	         "TIN        : " + this.TIN         + "\n" +
		     "First Name : " + this.Nm_Fst      + "\n" +
		     "Last Name  : " + this.Nm_Lst      + "\n" +
		     "Address    : " + this.Addr        + "\n" +
		     "Phone #1   : " + this.getPhn()    + "\n" +
		     "Phone #2   : " + this.getPhn2()   + "\n" +
	         "Email #1   : " + this.getEmail()  + "\n" +
             "Email #2   : " + this.getEmail2() + "\n";
	 }
   
   /*******************************************************************************
	Retrieves a formatted displayable list of the attribute values of the current
	<b>Customer</b> object
	<br><br>
	@return string - A <b><i>String</i></b> variable
   *******************************************************************************/
   public String getDisplayText()
    {
	  return toString();
    }
  }
